home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Grafik / Misc / ImageEnginer / ARexx / Batch / Preserve.ieb < prev    next >
Encoding:
Text File  |  1997-02-02  |  5.1 KB  |  199 lines

  1. /*
  2. ** $VER: Preserve.ieb 2.0, IE Arexx script
  3. ** Image Engineer Batch Processing script
  4. ** Copyright © by Patrik M Nydensten 
  5. ** 19/1 1997 Stockholm/Sweden
  6. **
  7. ** Presereve colors within selected hue range(s).
  8. ** Based on the IE arexx script Presereve 2.13.
  9. */
  10.  
  11. options results
  12. signal on error
  13.  
  14. parse arg input command
  15. input = upper(strip(input))
  16. address 'IMAGEENGINEER'
  17.  
  18. select  /* Required batch script commands */
  19.   when input = 'INFO' then    return get_info()
  20.   when input = 'CONFIG' then  return get_config(command)
  21.   when input = 'PROCESS' then return process_image(command)
  22.   otherwise do
  23.     'REQUEST' '"Failure in call to batch script!"' '" Quit "'
  24.     return '<ERROR>'
  25.   end
  26. end
  27.  
  28. exit 0
  29.  
  30. /* Required "Get_info" procedure  ------------------------------------ */
  31. /* S = SECONDARY, A = ALPHA, 1 = Single file, 2 = Multiple files       */
  32.  
  33. get_info:
  34.   back = 'OK'
  35. return back
  36.  
  37. /* Required "Get_config" procedure  ---------------------------------- */
  38.  
  39. get_config:
  40.   parse arg '"'command'"'
  41.   
  42.   LHueTol=-21 ; RHueTol=21
  43.                               
  44.   if command ~= '' then parse var command LHueTol RHueTol '#'Select '#'WorkType .
  45.  
  46.   'IE_TO_FRONT'
  47.  
  48.   form = 'FORM "Preserve" " Accept | Cancel "',
  49.     ' TEXT,"Preserves selected basecolors in image while'd2c(10)'unselected colors are made grey."'
  50.  
  51.   if command = '' then form = form ||' CHECKBOX,"Red (R)",1',
  52.     ' CHECKBOX,"Yellow (Y)",0',
  53.     ' CHECKBOX,"Green (G)",1',
  54.     ' CHECKBOX,"Cyan (C)",0',
  55.     ' CHECKBOX,"Blue (B)",1',
  56.     ' CHECKBOX,"Magenta (M)",0'
  57.   
  58.   form = form ||' INTEGER,"Left hue tolerance",-21,0,'strip(LHueTol)',SLIDER',
  59.     ' INTEGER,"Right hue tolerance",0,21,'strip(RHueTol)',SLIDER'
  60.   
  61.   if command = '' then form = form ||' CYCLE,"Work type:",'||,
  62.     '"Fields, (separate color areas)|Spread, (use areas between close colors)",0'
  63.  
  64.   form
  65.   
  66.   if command = '' then do
  67.     parse var result ok R Y G C B M LHueTol RHueTol WorkType .
  68.     Select = ''
  69.     if R then Select = Select||'R'
  70.     else Select = Select||'-'
  71.     if Y then Select = Select||'Y'
  72.     else Select = Select||'-'
  73.     if G then Select = Select||'G'
  74.     else Select = Select||'-'
  75.     if C then Select = Select||'C'
  76.     else Select = Select||'-'
  77.     if B then Select = Select||'B'
  78.     else Select = Select||'-'
  79.     if M then Select = Select||'M'
  80.     else Select = Select||'-'
  81.   end
  82.   else do
  83.     parse var result ok LHueTol RHueTol .
  84.     Select = '------'
  85.     WorkType = 'none'
  86.   end
  87.   if ok = 0 then return '<ERROR>'
  88.  
  89.   back = LHueTol RHueTol '#'Select '#'WorkType
  90. return back
  91.  
  92. /* Required "Process_image" procedure  ------------------------------- */
  93.  
  94. process_image:
  95.   parse arg '"'src_image'"' '"'dst_image'"' '"'options'"'
  96.   parse var options LHueTol RHueTol '#'Select '#'WorkType .
  97.  
  98.   'OPEN' '"'src_image'"' '24'
  99.   if (RC ~= 0) then do
  100.     'IE_TO_FRONT'
  101.     'REQUEST' '"Failed to load image:' d2c(10)||src_image'"' '" OK "'
  102.     return '<ERROR>'
  103.   end
  104.   else LoadImage = result
  105.  
  106.   'BRIGHTNESS' LoadImage '-255'
  107.   AlphaImage = Result
  108.  
  109.   do i = 0 to 5  /* alpha add-loop */
  110.     if substr(Select,i+1,1) ~= '-' then do
  111.     'HUE_MASK' LoadImage Fix_Hue((i*42.667)+get_HueTol('L')) Fix_Hue((i*42.667)+get_HueTol('R'))
  112.       MaskImage = Result
  113.   
  114.       'MARK' AlphaImage 'SECONDARY'
  115.     'MARK' MaskImage 'PRIMARY'
  116.   
  117.       'COMPOSITE' 0 0 'MAX'
  118.       NewAlpha = Result
  119.       'CLOSE' AlphaImage
  120.       'CLOSE' MaskImage
  121.     AlphaImage = NewAlpha
  122.     end
  123.   end
  124.   
  125.   'CONVERT_TO_GREY' LoadImage
  126.   GreyImage = Result
  127.   
  128.   'MARK' AlphaImage 'ALPHA'
  129.   'MARK' LoadImage 'PRIMARY'
  130.   'MARK' GreyImage 'SECONDARY'
  131.  
  132.   'COMPOSITE' 0 0 'ALPHA'
  133.   OutputImage = Result
  134.  
  135.   'CLOSE' GreyImage
  136.   'CLOSE' AlphaImage
  137.   'CLOSE' LoadImage
  138.  
  139.   if getclip('cfg_save_frmt')='' then setclip('cfg_save_frmt','ILBM CmpByteRun1')
  140.   'SAVE_DATA' OutputImage '"'dst_image'"' '"'getclip('cfg_save_frmt')'"'
  141.   if (RC ~= 0) then do
  142.     'IE_TO_FRONT'
  143.     'REQUEST' '"Failed to save image:' d2c(10)||dst_image'"' '" OK "'
  144.     return '<ERROR>'
  145.   end
  146.   'CLOSE' OutputImage
  147.  
  148.   back = 'OK'
  149. return back
  150.  
  151. /* Internal procedures  ---------------------------------------------- */
  152.  
  153. Fix_Hue:
  154.   parse arg Tol
  155.   if Tol < 0 then Back = 255 + trunc(Tol)
  156.   else if Tol > 255 then Back = trunc(Tol) - 255
  157.   else Back = trunc(Tol)
  158. return Back
  159.  
  160. Get_HueTol:
  161.   parse arg Type
  162.   if Type = 'L' then do
  163.     if WorkType = 0 then Back = LHueTol
  164.     else do
  165.       newi = i
  166.       if newi=0 then newi = 6
  167.       if substr(Select,newi,1) ~= '-' then Back = -21
  168.       else Back = LHueTol
  169.     end
  170.   end
  171.   else do
  172.     if WorkType = 0 then Back = RHueTol
  173.     else do
  174.       newi = i+2
  175.       if newi=7 then newi = 1
  176.       if substr(Select,newi,1) ~= '-' then Back = 21
  177.       else Back = RHueTol
  178.     end
  179.   end
  180. return Back
  181.  
  182. /*******************************************************************/
  183. /* This is where control goes when an error code is returned by IE */
  184. /* It puts up a message saying what happened and on which line     */
  185. /*******************************************************************/
  186.  
  187. error:
  188. if RC=5 then do
  189.     IE_TO_FRONT
  190.     LAST_ERROR
  191.     'REQUEST "'||RESULT||'"'
  192. end
  193. else do
  194.     IE_TO_FRONT
  195.     LAST_ERROR
  196.     'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!'
  197. end
  198. return '<ERROR>'
  199.